﻿@using Seal.Model;
@{
    MetaTable table = Model;

    //Parameters for this table
    table.Parameters.Add(new Parameter() { Name = "excel_path", Value = "", DisplayName = "Excel File Path", Description = "The Excel file path (*.xlsx). The path can contain the '%SEALREPOSITORY%' keyword to specify the repository path.", Enums = new string[] { @"%SEALREPOSITORY%/Databases/databank.worldbank.org_health_population.xlsx" }, UseOnlyEnumValues = false });
    table.Parameters.Add(new Parameter() { Name = "excel_tab", Value = "", DisplayName = "Tab name", Description = "The Tab name of the Excel Sheet used to load the table. If empty, the first tab is used." });
    table.Parameters.Add(new Parameter() { Name = "excel_start_row", NumericValue = 1, DisplayName = "Start row", Description = "The start row of the tab to define the table." });
    table.Parameters.Add(new Parameter() { Name = "excel_start_col", NumericValue = 1, DisplayName = "Start column", Description = "The start column of the tab to define the table." });
    table.Parameters.Add(new Parameter() { Name = "excel_end_row", NumericValue = 0, DisplayName = "End row", Description = "The end row to define the table. If 0, rows are taken until an empty row is found." });
    table.Parameters.Add(new Parameter() { Name = "excel_end_col", NumericValue = 0, DisplayName = "End column", Description = "The end column to define the table. If 0, columns are taken until an empty column is found." });
    table.Parameters.Add(new Parameter() { Name = "excel_header", BoolValue = true, DisplayName = "Has header", Description = "If true, the first line is used to get the column names otherwise column names are automatic." });

    table.DefinitionScript = @"@using System.IO
@using System.Data
@{
    MetaTable metaTable = Model;

    var path = metaTable.GetValue(""excel_path"").Replace(Repository.SealRepositoryKeyword, Repository.Instance.RepositoryPath);
    if (metaTable.NoSQLCacheTable != null && File.GetLastWriteTime(path) <= metaTable.LoadDate) {
        metaTable.LogMessage(""Getting table from the load done at {0}."", metaTable.LoadDate);
        metaTable.NoSQLTable = metaTable.NoSQLCacheTable;
    }
    else {
        metaTable.NoSQLTable = DataTableLoader.FromExcel(path, metaTable.GetValue(""excel_tab""), metaTable.GetNumericValue(""excel_start_row""), metaTable.GetNumericValue(""excel_start_col""), metaTable.GetNumericValue(""excel_end_row""), metaTable.GetNumericValue(""excel_end_col""), metaTable.GetBoolValue(""excel_header"", true));
    }
}";

    table.LoadScript = @"";
}

